﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
    <script src="javascripts/echarts.js"></script>
    <script src="javascripts/jquery-3.1.0.min.js"></script>
    <script src="javascripts/ajaxmanager.js"></script>

	<style> /* 设置DIV全屏显示 */
	html,body{height:100%;}
	#main{
		height:auto!important; /*for ie6 bug and ie7+,moz,webkit 正确*/
		height:100%; /*修复IE6,all browser*/
		min-height:100%; /*for ie6 bug and ie7+,moz,webkit 正确*/
	}
　　</style>

   <script type="text/javascript">
       $(document).ready(function () {
           $("#btnFresh").click(function () {
               var myChart = echarts.init(document.getElementById('main'));
               // 显示标题，图例和空的坐标轴
               myChart.setOption({
                   title: {
                       text: 'bar chart of TAT'
                   },
                   tooltip: {},
                   legend: {
                       data: ['tat']
                   },
                   toolbox: {
                       feature: {
                           saveAsImage: {}
                       }
                   },
                   xAxis: {
                       data: []
                   },
                   yAxis: {},
                   series: [{
                       name: 'tat',
                       type: 'bar',
                       data: []
                   }]
               });

               //console.log('btn fresh clicked...');
               myChart.showLoading();

               /*
               Ajax("tat", {
                   data: {
                       start: "2016-07-01",//$("#start_date").val().toString(),
                       end: "2016-08-01"//$("#end_date").val().toString()
                   }, 'method': 'post'
               }, function (data) {
                   myChart.hideLoading();
                   if (data) {
                       myChart.setOption({
                           xAxis: {
                               data: data.minutes
                           },
                           series: [{
                               name: 'tat',
                               data: data.tat
                           }]
                       });
                   }
               }, function () {
                   alert("system error!");
               });
               */

               //not sucssfull....
               
               var option={
                   type:"POST",
                   url: "tatcount",
                   //contentType:"application /json;charset:utf-8",
                   //dataType:"json",
                   data:{
                       start: $("#start_date").val(),
                       end: $("#end_date").val()
                   },
                   success:function(response){
                       //console.log(response);
                       myChart.hideLoading();
                       // 填入数据
                       myChart.setOption({
                           xAxis: {
                               data: response.minutes
                           },
                           series: [{
                               // 根据名字对应到相应的系列
                               name: 'tat',
                               data: response.tat
                           }]
                       });
                    },
                   error:function(err){
                       alert(err);
                    }
               }

               $.ajax(option);
               


           })
       });
    </script>
</head>

<body onload="initbody();">
    <script type="text/javascript">
        function Date2Str(x, y) {
            var z = { M: x.getMonth() + 1, d: x.getDate(), h: x.getHours(), m: x.getMinutes(), s: x.getSeconds() };
            y = y.replace(/(M+|d+|h+|m+|s+)/g, function (v) { return ((v.length > 1 ? "0" : "") + eval('z.' + v.slice(-1))).slice(-2) });
            return y.replace(/(y+)/g, function (v) { return x.getFullYear().toString().slice(-v.length) });
        }

        function initbody(){
            var start_date = document.getElementById("start_date");
            var end_date = document.getElementById("end_date");

            //var year = Date.now.toString("yyyy-MM-dd");
            //var month = Date.now.toString("MM");
            //var day = Date.now.toString("dd");

            //var dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
            
            var today = new Date();
            var dateString = Date2Str(today, "yyyy-MM-dd"); //+ "-" + month + "-" + day;

            //console.log(dateString);
            //$("btnFresh").val(dateString);
            start_date.value = dateString;
            end_date.value = dateString;
    }
    </script>

    <input id="start_date" type="date" value="2016-07-01"/>
    <input id="end_date" type="date" value="2016-09-01"/>
    <input id="btnFresh" type="button" value="Fresh" />

	<!--<style>"width:100%;height:100%;"</style>-->
    <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
    <!--<div id="main" style="width: 600px;height:400px;"></div>-->
	<!--style="width:100%;height:100%;"-->
	<div id="main"></div>
    <script type="text/javascript">
        var myChart = echarts.init(document.getElementById('main'));
        // 显示标题，图例和空的坐标轴
        myChart.setOption({
            title: {
                text: 'bar chart of TAT'
            },
            tooltip: {},
            legend: {
                data: ['tat']
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                data: []
            },
            yAxis: {},
            series: [{
                name: 'tat',
                type: 'bar',
                data: []
            }]
        });

        // 异步加载数据
        myChart.showLoading();
        $.get('tatcount').done(function (data) {
            myChart.hideLoading();
            // 填入数据
            myChart.setOption({
                xAxis: {
                    data: data.minutes
                },
                series: [{
                    // 根据名字对应到相应的系列
                    name: 'tat',
                    data: data.tat
                }]
            });
        });

        // 使用刚指定的配置项和数据显示图表。
        //myChart.setOption(option);
    </script>
</body>
</html>